package team119;

import battlecode.common.Clock;
import battlecode.common.Direction;
import battlecode.common.GameConstants;
import battlecode.common.RobotController;
import battlecode.common.RobotType;

/** The example funcs player is a player meant to demonstrate basic usage of the most common commands.
 * Robots will move around randomly, occasionally mining and writing useless messages.
 * The HQ will spawn soldiers continuously. 
 */
public class RobotPlayer 
{
	public static void run(RobotController rc) {
		
		while (true) {
			try {
				BOT currentBot=null;
				if (rc.getType() == RobotType.HQ) 
				{
					currentBot=new BOTHeadquarters();
				}
				else if (rc.getType() == RobotType.SOLDIER) 
				{
					
					currentBot=new BOTSoldier();
					
					if(ShouldCreateDefensiveBot()) {
						currentBot.instanceVariables.isDefensiveRobot = true;
					} else if (Clock.getRoundNum() < 3*GameConstants.HQ_SPAWN_DELAY) {
						currentBot.instanceVariables.isCaptureBot = true;
					}
				}
				
				if(currentBot!=null)
					currentBot.RunBot(rc);
				// End turn
				rc.yield();
			} 
			catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	private static boolean ShouldCreateDefensiveBot() {
		int roundNum = Clock.getRoundNum();
		
		if (roundNum < GameConstants.HQ_SPAWN_DELAY + 2){//GameConstants.HQ_SPAWN_DELAY/2) {
			return true;
		}
		return ((roundNum < GameConstants.HQ_SPAWN_DELAY * 19) && roundNum > (GameConstants.HQ_SPAWN_DELAY * 6) && (roundNum % (GameConstants.HQ_SPAWN_DELAY * 6) < GameConstants.HQ_SPAWN_DELAY/2 || ((roundNum % (GameConstants.HQ_SPAWN_DELAY * 6)) - (GameConstants.HQ_SPAWN_DELAY * 6))*-1 < GameConstants.HQ_SPAWN_DELAY/2));
	}
}
